package everyday3;

import CommonStructure.TreeNode;

/**
 * @Author: Siantar
 * @Date: 2023-07-14-21:59
 * @Description: 1.0
 */
public class T0979 {
    int move = 0;

    public int distributeCoins(TreeNode root) {
        dfs(root);
        return move;
    }

    public int dfs(TreeNode node) {
        if (node == null) return 0;
        int left = dfs(node.left), right = dfs(node.right);
        move += Math.abs(left) + Math.abs(right);
        return node.val + left + right-1;
    }
}
